# for循环和while完成计数
e = 0
for e in range(100):
    print(e)

e = 0
while e < 100:
    print(e)
    e += 1

# 用for循环和while循环两种方式来实现斐波那契函数, 限制在100以内
l = []
e = 0
n1 = 0
n2 = 1
n = 0
for n in range(100):
    if e == 0:
        l.append(0)
    elif e == 1:
        l.append(1)
    else:
        n = n1 + n2
        n1 = n2
        n2 = n
    e += 1
    if n > 100:
        break
    l.append(n)


while True:
    if e == 0:
        l.append(0)
    elif e == 1:
        l.append(1)
    else:
        n = n1 + n2
        n1 = n2
        n2 = n
    e += 1
    if n > 100:
        break
    l.append(n)

print(l)

# 添加自定义异常
class ParamsError(Exception):
    def __init__(self, expression, message):
        super().__init__(expression, message)
        self.expression = expression
        self.message = message

def add(a,b):
    try:
        return a / b
    except ZeroDivisionError:
        raise ParamsError("分母不能为0")
    finally:
        print("function my_sub end")

print(add(1,0))